package com.ruoyi.project.sysmanage.controller;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.sysmanage.domain.Cost;
import com.ruoyi.project.sysmanage.domain.Registration;
import com.ruoyi.project.sysmanage.service.RegistrationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.security.Security;
import java.util.Date;
import java.util.List;

/**
 * @author : 代学欣
 * @date : 20:28 2021/7/14
 */
@RestController
@RequestMapping("/sysmanage/registration")
public class RegistrationController extends BaseController {
    @Autowired
    private RegistrationService registrationService;
    /**
     * 获取所有检查费用列表
     */
    @PreAuthorize("@ss.hasPermi('sysmanage:registration:query')")
    @GetMapping("list")
    public TableDataInfo list(Registration registration){
        //分页查询,处理请求参数pageNum,pageSize等。并使用PageHelper处理分页查询
        startPage();
        //调用service查询数据库
        List<Registration> list = registrationService.selectList(registration);
        //返回
        return getDataTable(list);
    }

    /**
     * 添加挂号费用
     * @param registration
     * @return
     */
    @PreAuthorize("@ss.hasPermi('sysmanage:registration:add')")
    @PostMapping
    public AjaxResult addRegistration(@RequestBody Registration registration){
        registration.setCreateBy(SecurityUtils.getUsername());
        int rows = registrationService.addRegistration(registration);
        return toAjax(rows);
    }

    /**
     * 修改前的查询显示,获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('sysmanage:registration:query')")
    @GetMapping("/{reg_id}")
    public AjaxResult getById(@PathVariable Integer reg_id){
        Registration registration = registrationService.getById(reg_id);
        return AjaxResult.success(registration);
    }

    /**
     * 修改挂号费用参数
     * @param registration
     * @return
     */
    @PreAuthorize("@ss.hasPermi('sysmanage:registration:update')")
    @PutMapping
    public AjaxResult editCost(@RequestBody Registration registration){
        registration.setUpdateBy(SecurityUtils.getUsername());
        int rows = registrationService.updateRegistration(registration);
        return toAjax(rows);
    }

    /**
     * 检查费用的删除
     * @param reg_ids
     * @return
     */
    @PreAuthorize("@ss.hasPermi('sysmanage:registration:delete')")
    @DeleteMapping("/{reg_ids}")
    public AjaxResult romoveCost(@PathVariable Integer[] reg_ids){
        int rows = registrationService.deleteRegistration(reg_ids);
        return toAjax(rows);
    }
}
